#include "test.h"
#include <stdio.h>


int executed = 0;
int successes = 0;
int failures = 0;


void test_try(const char* testname, const char* file, int lineno)
{
  ++executed;
}


void test_failure(const char* testname, const char* file, int lineno)
{
  fprintf(stderr, "test %s failed (%s:%d)\n", testname, file, lineno);
  ++failures;
}


void test_success(const char* testname, const char* file, int lineno)
{
  ++successes;
}


void test_report()
{
  if (executed != failures + successes) {
    fprintf(stderr, "WARNING: some test may be still running (");
    fprintf(stderr, "%d started, %d completed)\n", executed, failures + successes);
  }
  if (executed == 0) {
    fprintf(stderr, "No test executed\n");
  } else if (failures == 0) {
    fprintf(stderr, "All tests passed (%d tests completed)\n", executed);
  } else {
    fprintf(stderr, "Some test failed (%d tests completed, %d successes, %d failures)\n",
	   executed, successes, failures);
  }
}


void test_assertion_failed(const char* filename, int lineno)
{
  fprintf(stderr, "test assertion failed (%s:%d)\n", filename, lineno);
}
